package healththink



import grails.test.mixin.*
import org.junit.*

/**
 * See the API for {@link grails.test.mixin.domain.DomainClassUnitTestMixin} for usage instructions
 */
@TestFor(FacilityGroupUserLink)
@Mock([User, FacilityGroup])
class FacilityGroupUserLinkTests {

	@Test
    void testFacilityGroupUserLink() {
		
		def fgulTest = HealthThink.getStaticFacilityGroupUserLink()
		mockForConstraintsTests(FacilityGroupUserLink, [fgulTest])
		def fgulTest1 = new FacilityGroupUserLink()
		assertFalse fgulTest1.validate()
		assertEquals "nullable", fgulTest1.errors["userType"]
		
		FacilityGroup fg = HealthThink.getStaticFacilityGroup()
		User user = HealthThink.getStaticUser()
		
		FacilityGroupUserLink target = FacilityGroupUserLink.link(user, fg)
		target.userType = UserType.Owner
		
		assertNotNull("(error)FacilityGroupUserLink Target Null", target)
		assertNotNull("(error)FacilityGroupUserLink Validation Was Not Successfull", target.validate())
		assertFalse("(error)FacilityGroupUserLink Has Errors", target.hasErrors())
		
		target = target.save(flush:true)
		FacilityGroupUserLink expected = FacilityGroupUserLink.findById(target.id)
		
		assertNotNull("(error)FacilityGroupUserLink Target was not saved", target)
		assertNotNull("(error)Expected FacilityGroupUserLink was null", expected)
		assertEquals("(error)Target and Expected are not Equal", target, expected)
		   
		target.delete(flush:true)
    }
}
